<template>
  <div id="home" class="home">
    <!-- 搜索框 -->
    <van-search v-model="seachData" placeholder="商品搜索 共239款好物" input-align="center"/>
    <!-- 轮播图 -->
    <van-swipe :autoplay="3000" :width='375' :height='200'>
      <van-swipe-item v-for="(image, index) in images" :key="index" >
        <img class="swaperIMG" v-lazy="image.image_url" />
      </van-swipe-item>
    </van-swipe>
    <!-- 5个图标  导航 -->
    <van-grid :column-num="5">
      <van-grid-item v-for="(item,index) in channel" :key="'banner'+index" :icon="item.icon_url" :text="item.name" />
    </van-grid>
    <!--品牌供应商直供  -->
    <div class="brandList">
      <van-panel title="品牌供应商直供" >
        <van-grid  :column-num="2">
          <van-grid-item v-for="(product1,index1) in brandList" :key="'product1'+index1">
            <van-image  lazy-load :src="product1.new_pic_url" />
            <h4 class="title">{{product1.name}}</h4>
            <p class="price">{{product1.floor_price}}元起</p>
          </van-grid-item>
        </van-grid>
      </van-panel>
    </div>
     <!--新品首发  -->
    <div class="newGoodsList">
      <van-panel title="新品首发" >
        <van-grid  :column-num="2">
          <van-grid-item v-for="(newGoods,index2) in newGoodsList" :key="'newGoods'+index2">
            <van-image  lazy-load :src="newGoods.list_pic_url" />
            <h5 class="title">{{newGoods.name}}</h5>
            <p class="price">{{newGoods.retail_price}}元起</p>
          </van-grid-item>
        </van-grid>
      </van-panel>
    </div>
    <!--人气推荐  -->
    <div class="hotGoodsList">
      <van-panel title="人气推荐" >
        <van-card v-for="(hotlist,index) in hotGoodsList" :key="'hotlist'+index"
          :price="hotlist.retail_price+'元'"
          :desc="hotlist.goods_brief"
          :title="hotlist.name"
          :thumb="hotlist.list_pic_url"
        />
      </van-panel>
    </div>
    <!-- 专题精选 -->
   <div class="topicList">
    <van-panel title="专题精选" >
        <van-swipe :autoplay="3000" :width='375' :height='200'>
          <van-swipe-item v-for="(image, index) in topicList" :key="index">
            <img class="topicListIMG" v-lazy="image.item_pic_url" />
          </van-swipe-item>
        </van-swipe>
    </van-panel>
   </div>
     <!--居家  -->
     
    <div class="hotGoodsList" v-for="(item4,index) in categoryList" :key="'item4'+index">
      <van-panel :title="item4.name" >
         <van-grid  :column-num="2">
          <van-grid-item v-for="(goodlist1,goodindex2) in item4.goodsList" :key="'newGoods'+goodindex2">
            <van-image  lazy-load :src="goodlist1.list_pic_url" />
            <h6 class="title">{{goodlist1.name}}</h6>
            <p class="price">{{goodlist1.retail_price}}元起</p>
          </van-grid-item>
        </van-grid>
      </van-panel>
    </div>
   
    <!-- 设置底部边距 显示所有内容-->
    <div style="height:50px"></div>
    <!-- 底部导航栏 -->
    <tab-btn></tab-btn>
  </div>
</template>

<script>
// @ is an alias to /src
import axios from 'axios';
import api from '../assets/config/api';
import Vue from 'vue';
import { Lazyload } from 'vant';
import tabBtn from '../components/tabBtn.vue'
Vue.use(Lazyload);

export default {
  name: 'Home',
  data:function(){
    return {
     seachData:"",
     data:{},
    
    }
  },
  computed:{
    images:function(){
      if(typeof this.data.banner =='object'){
          return this.data.banner
      }else{
        return []
      }
    },
    channel:function(){
      if(typeof this.data.channel=='object'){
        return this.data.channel
      }else{
        return []
      }
    },
    brandList:function(){
      if(typeof this.data.brandList=='object'){
        return this.data.brandList
      }else{
        return []
      }
    },
    newGoodsList:function(){
      if(typeof this.data.newGoodsList=='object'){
        return this.data.newGoodsList
      }else{
        return []
      }
    },
    hotGoodsList:function(){
      if(typeof this.data.hotGoodsList=='object'){
          return this.data.hotGoodsList
      }else{
        return []
      }
    },
    categoryList:function(){
      if(typeof this.data.categoryList =='object'){
        return this.data.categoryList
      }else{
        return []
      }
    },
    topicList:function(){
      if(typeof this.data.topicList =='object'){
          return this.data.topicList
      }else{
        return []
      }
    }
  },
  components: {
    tabBtn
  },

  async mounted(){
    // console.log(api.IndexUrl);
    let res=await axios.get(api.IndexUrl);
    this.data=res.data.data;
    //测试
     console.log(this.data);
   
  }, 
}
</script>
<style lang="less">
#home{
  .van-grid-item{
    overflow: hidden;
  }
  .swaperIMG{  
    width: 375px;
    height: 200px;
  }
  .brandList{
    .van-grid-item__content{
      padding: 0px;
    }
    .van-grid-item{
      border: 1px solid #fff;
    }
    .title{
      position: absolute;
      top: 10px;
      left: 10px;
  }
    .price{
      position: absolute;
      top: 38px;
      left: 10px;
      font-size: 14px;
      color: #999;
  }
  }
  .newGoodsList{
    .title{
      width: 90%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .price{
     font-size: 14px;
     color: #999;
     position: absolute;
     bottom: 5px;
     
    }
  }
  .hotGoodsList{
    .van-card__content{
      justify-content: center;
      text-align: left;
    }
    .van-card__price{
      color: red;
      
    }
    .van-card__price-integer{
      font-size: 12px;
    }
    .van-card__title {
      font-weight: 900px;
      font-size: 14px;
      color: #333;
      padding: 5px 0;
    }
     .title{
      width: 90%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .price{
     font-size: 14px;
     color: #999;
     position: absolute;
     bottom: 5px;
    }
  }
  .topicList{
    .topicListIMG{
      width: 375px;
      height: 200px;
    }
  }
}
</style>


